﻿using System;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Microsoft.Practices.ServiceLocation;
using KandaAlpha.Application.Interfaces;
using KandaAlpha.Domain.Model.Entities;

namespace KandaAlpha.UI
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

            // get the customer service using IoC (Unity)
            var custService = ServiceLocator.Current.GetInstance<ICustomerService>();

            // get all customers and bind to grid
            dgCustomers.DataSource = custService.GetAll();
            dgCustomers.DataBind();

            // use a specific method on customer repository
            var kp = custService.GetBestCustomer();

            // display customer's full name 
            litCustomerName.Text = kp.FullName;

            // demonstrate lazy/deferred loading (not for production!)
            litFirstOrderTotal.Text += kp.Orders.First().OrderTotal.ToString();

        }
    }
}